<template>
  <div class="zc-topbar">
    <div class="wrapper clearfix">
      <div class="zc-login-info"> <span class="zc-back-home"><a  @click="$router.push('/')">商城首页</a></span>
        <span v-if="userName == '登录'" key='NOshowUserName'> <span class="zc-login">Hi~欢迎来到易创天下，请<a @click="$router.push('/Login')">登录</a></span>
          <span class="zc-register">
            <a @click="$router.push('/reg')">免费注册</a></span></span>
        <span v-else key='showUserName'> <span class="zc-login">Hi~欢迎<a>{{userName}}</a>来到易创天下，<a @click="handleLoginOut">退出</a></span>
        </span>
      </div>
      <ul class="zc-quick-menu">
        <li><a @click="$router.push('/order')">我的订单</a></li>
        <li><a>购物车</a></li>
        <li class="zc-separator">|</li>
        <li class="zc-mobile"> <a class="zc-hd zc-mobile-hd">手机商城<i class="ico"></i></a>
          <div class="zc-mobile-bd" id="zc-mobile-bd">
            <img src="../pages/image/shop.png" width="130" height="130">
          </div>
        </li>
        <li class="lianxikefu"> <a href="javascript:;" class="zc-hd">联系客服<i class="ico"></i></a>
          <div class="Triangle"></div>
          <div class="zc-service-tel">400-180-2011</div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import * as API from '@/api/index'
  export default {
    name: 'headers',
    data() {
      return {
        userName: localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')).shop_user_name : '登录'
      }
    },
    methods: {
    async  handleLoginOut() {
        const data = {
          service: 'Pro.User.UserOut'
        };
        const res = await API.toIndex(data);
        if (res.ret == 200) {
          await this.$store.dispatch('logOut');
           localStorage.removeItem('userInfo')
          setTimeout(() => {
            this.$router.push('/login')
          }, 500)
        }
      }
    },
  }

</script>
<style lang="css" scoped>
  @import "../scss/index.css";

 .Triangle {
    position: absolute;
    top: 30px;
    right: 48px;
    font-size: 0;
    line-height: 0;
    border-width: 10px;
    border-color: #ededed;
    display: none;
    border-top-width: 0;
    border-style: dashed;
    border-bottom-style: solid;
    border-left-color: transparent;
    border-right-color: transparent;
  }
  /* .Triangle {
    width: 80%;
    position: absolute;
    top: 40px;
    right: 0;
    display:none;
  }

  .Triangle:before {
    content: '';
    position: absolute;
    right: -10px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    left: 17%;
    margin-left: -12px;
    top: -10px;
    border-bottom: 10px solid #ededed;
  }

  .Triangle:after {
    content: '';
    position: absolute;
    top: 11px;
    width: 0;
    height: 0;
    border-right: 9px solid transparent;
    border-left: 9px solid transparent;
    left: 17%;
    margin-left: -11px;
    top: -9px;
    border-bottom: 9px solid #fff;
  }*/

</style>
